package cn.homework.day07;

import java.util.Comparator;
import java.util.Scanner;
import java.util.TreeSet;

public class Demo2 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        TreeSet<Book> list = new TreeSet<>(new Comparator<Book>() {
            @Override
            public int compare(Book o1, Book o2) {
                if (o1.getPrice() > o2.getPrice()) {
                    return 1;
                } else if (o1.getPrice() < o2.getPrice()) {
                    return -1;
                } else {
                    return o1.getName().compareTo(o2.getName());
                }
            }
        });
        // TreeSet<Book> list1 = new TreeSet<>((o1, o2) -> );
        int index = 1;
        while (index <= 3) {
            System.out.println("请输入第" + index + "本书的名称:");
            String name = sc.next();
            System.out.println("请输入第" + index + "本书的价格(整数):");
            int price = sc.nextInt();
            list.add(new Book(name, price));
            System.out.println(name + "添加成功，继续添加请输入1，输入其他数字将结束！");
            int num = sc.nextInt();
            if (num != 1)
                break;
            index++;
        }
        System.out.println("您一共添加了：" + list.size() + "本书，分别是：" + list);
        //自然排序

    }
}
